using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using System;

namespace PrismDemo.ViewModels.Dialogs
{
    public class NotificationDialogViewModel : BindableBase, IDialogAware
    {
        private string _title = "通知";
        private string _message = "";
        private bool _showIcon = true;

        public NotificationDialogViewModel()
        {
            OkCommand = new DelegateCommand(Ok);
        }

        #region Properties

        public string Title
        {
            get { return _title; }
            set { SetProperty(ref _title, value); }
        }

        public string Message
        {
            get { return _message; }
            set { SetProperty(ref _message, value); }
        }

        public bool ShowIcon
        {
            get { return _showIcon; }
            set { SetProperty(ref _showIcon, value); }
        }

        #endregion

        #region Commands

        public DelegateCommand OkCommand { get; }

        #endregion

        #region Command Methods

        private void Ok()
        {
            RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
        }

        #endregion

        #region IDialogAware

        public string DialogTitle => Title;

        public event Action<IDialogResult>? RequestClose;

        public bool CanCloseDialog() => true;

        public void OnDialogClosed()
        {
            // 对话框关闭时的清理工作
        }

        public void OnDialogOpened(IDialogParameters parameters)
        {
            // 获取传入的参数
            if (parameters.ContainsKey("title"))
            {
                Title = parameters.GetValue<string>("title");
            }

            if (parameters.ContainsKey("message"))
            {
                Message = parameters.GetValue<string>("message");
            }

            if (parameters.ContainsKey("showIcon"))
            {
                ShowIcon = parameters.GetValue<bool>("showIcon");
            }
        }

        #endregion
    }
}